package com.mlx.meng.author;

import com.mlx.meng.tool.DataPermissionUtil;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;


public class WhiteListCollector {

    protected String getUserId(){
        return null;
    }

    protected Collection<String> listWhiteUserIdCollection(){
        return new HashSet<>();
    }

    private Set<String> buildWhiteList(){
        Collection<String> whiteUserIdCollection = listWhiteUserIdCollection();

        return DataPermissionUtil.isEmpty(whiteUserIdCollection) ? new HashSet<>() : new HashSet<>(whiteUserIdCollection);
    }

    public boolean isInWhiteList(){
        Set<String> whiteList = buildWhiteList();
        return whiteList.contains(getUserId());
    }

    public boolean isNotInWhiteList(){
        return !(isInWhiteList());
    }
}
